﻿using System;
using System.Collections;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using Antu.WorkFlowFactory;
using Antu.Core.Services;

namespace WebSys.UI.OfficeFlow
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class ShowImage : IHttpHandler
    {
        FlowFactoryProvider _FlowFactoryProvider = (FlowFactoryProvider)ProviderService.ProviderServiceMange.GetProvider("FlowFactoryProvider");
        public void ProcessRequest(HttpContext context)
        {
            if (!string.IsNullOrEmpty(context.Request["aid"]))
            {
                string strSql = "select  *  from  st_attachment where aid='" + context.Request["aid"] + "'";
                DataTable ds = _FlowFactoryProvider.GetOneDs("(" + strSql + ")", "*", "").Tables[0];
                if (ds != null && ds.Rows.Count > 0 && ds.Rows[0]["DATA"] != null)
                {
                    context.Response.ClearContent();
                    context.Response.ContentType = string.Format("image/{0}", ds.Rows[0]["EXT_NAME"].ToString().TrimStart('.'));
                    byte[] bArr = ds.Rows[0]["DATA"] as Byte[];
                    context.Response.BinaryWrite(bArr);//此处bArr数组为null
                }
            }
            else
            {
                context.Response.ContentType = "image/Gif";
                context.Response.Write("暂无图片显示");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
